package com.aiyige.utils.widget.articleview.model;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Created by zhuyakun on 2018/3/13.
 */

public class ArticleNode implements Parcelable {
    public static final int NODE_TYPE_TEXT = 1;
    public static final int NODE_TYPE_PHOTO = 2;
    public static final int NODE_TYPE_VIDEO = 3;

    public static final int TEXT_STYLE_UNDEFINED = 0;
    public static final int TEXT_STYLE_BIG_TITLE = 1;
    public static final int TEXT_STYLE_SMALL_TITLE = 2;
    public static final int TEXT_STYLE_MAIN_BODY = 3;

    String text;
    String url;
    String coverUrl;
    boolean needUpload;
    int type;
    int textStyle;
    long duration;
    long size;
    boolean expand;
    int uploadFileId;

    public ArticleNode() {
    }

    private ArticleNode(Builder builder) {
        setText(builder.text);
        setUrl(builder.url);
        setCoverUrl(builder.coverUrl);
        setNeedUpload(builder.needUpload);
        setType(builder.type);
        setTextStyle(builder.textStyle);
        setDuration(builder.duration);
        setSize(builder.size);
        setExpand(builder.expand);
        setUploadFileId(builder.uploadFileId);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getCoverUrl() {
        return coverUrl;
    }

    public void setCoverUrl(String coverUrl) {
        this.coverUrl = coverUrl;
    }

    public boolean isNeedUpload() {
        return needUpload;
    }

    public void setNeedUpload(boolean needUpload) {
        this.needUpload = needUpload;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getTextStyle() {
        return textStyle;
    }

    public void setTextStyle(int textStyle) {
        this.textStyle = textStyle;
    }

    public long getDuration() {
        return duration;
    }

    public void setDuration(long duration) {
        this.duration = duration;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public boolean isExpand() {
        return expand;
    }

    public void setExpand(boolean expand) {
        this.expand = expand;
    }

    public int getUploadFileId() {
        return uploadFileId;
    }

    public void setUploadFileId(int uploadFileId) {
        this.uploadFileId = uploadFileId;
    }

    public static final class Builder {
        private String text;
        private String url;
        private String coverUrl;
        private boolean needUpload;
        private int type;
        private int textStyle;
        private long duration;
        private long size;
        private boolean expand;
        private int uploadFileId;

        private Builder() {
            text = "";
            url = "";
            coverUrl = "";
            needUpload = true;
            type = NODE_TYPE_TEXT;
            duration = 0;
            size = 0;
            expand = false;
            textStyle = TEXT_STYLE_MAIN_BODY;
            uploadFileId = 0;
        }

        public Builder text(String text) {
            this.text = text;
            return this;
        }

        public Builder url(String url) {
            this.url = url;
            return this;
        }

        public Builder coverUrl(String coverUrl) {
            this.coverUrl = coverUrl;
            return this;
        }

        public Builder needUpload(boolean needUpload) {
            this.needUpload = needUpload;
            return this;
        }

        public Builder type(int type) {
            this.type = type;
            return this;
        }

        public Builder textStyle(int textStyle) {
            this.textStyle = textStyle;
            return this;
        }

        public Builder duration(long duration) {
            this.duration = duration;
            return this;
        }

        public Builder size(long size) {
            this.size = size;
            return this;
        }

        public Builder expand(boolean expand) {
            this.expand = expand;
            return this;
        }

        public Builder uploadFileId(int uploadFileId) {
            this.uploadFileId = uploadFileId;
            return this;
        }

        public ArticleNode build() {
            return new ArticleNode(this);
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.text);
        dest.writeString(this.url);
        dest.writeString(this.coverUrl);
        dest.writeByte(this.needUpload ? (byte) 1 : (byte) 0);
        dest.writeInt(this.type);
        dest.writeInt(this.textStyle);
        dest.writeLong(this.duration);
        dest.writeLong(this.size);
        dest.writeByte(this.expand ? (byte) 1 : (byte) 0);
        dest.writeInt(this.uploadFileId);
    }

    protected ArticleNode(Parcel in) {
        this.text = in.readString();
        this.url = in.readString();
        this.coverUrl = in.readString();
        this.needUpload = in.readByte() != 0;
        this.type = in.readInt();
        this.textStyle = in.readInt();
        this.duration = in.readLong();
        this.size = in.readLong();
        this.expand = in.readByte() != 0;
        this.uploadFileId = in.readInt();
    }

    public static final Creator<ArticleNode> CREATOR = new Creator<ArticleNode>() {
        @Override
        public ArticleNode createFromParcel(Parcel source) {
            return new ArticleNode(source);
        }

        @Override
        public ArticleNode[] newArray(int size) {
            return new ArticleNode[size];
        }
    };
}
